#include <iostream>
#include <string>
#include <vector>

class StringHelper
{
public:
    // news.music.pop
    // news..music.pop
    static int split(const std::string& str, const std::string& sep, std::vector<std::string>& result)
    {
        int pos = 0;
        int index = 0;
        while(index < str.size())
        {
            pos = str.find(sep, index);
            if(pos == std::string::npos)
            {
                result.push_back(str.substr(index));
                break;
            }
            if(pos != index) 
            {
                result.push_back(str.substr(index, pos-index));
            }
            index = pos + sep.size();
        }
        return result.size();
    }

    static std::vector<std::string> split(const std::string& str, const std::string& sep)
    {
        int pos = 0;
        int index = 0;
        std::vector<std::string> result;
        while(index < str.size())
        {
            pos = str.find(sep, index);
            if(pos == std::string::npos)
            {
                result.push_back(str.substr(index));
                break;
            }
            if(pos != index) 
            {
                result.push_back(str.substr(index, pos-index));
            }
            index = pos + sep.size();
        }
        return result;
    }
};

int main()
{
    std::string str = "...news..music.pop.#...";
    std::string sep = ".";

    std::vector<std::string> res;
    std::cout << StringHelper::split(str, sep, res) << std::endl;
    for(auto& a : res)
    {
        std::cout << a << std::endl;
    }

    std::vector<std::string> arr = StringHelper::split(str, sep);
    for(auto& a : arr)
    {
        std::cout << a << std::endl;
    }
    
    return 0;
}